<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增次品</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.validate.method.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/json2.js"></script>

<style type="text/css">
    body{ font-size:12px;}
    .l-table-edit {}
    .l-table-edit-td{ padding:4px;}
    .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .l-verify-tip{ left:230px; top:120px;}
    .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
	.p-tab .s-lab{font-size:12px;font-family:"微软雅黑",​"宋体",​Arial,​sans-serif;}
	input.l-textarea{width:170px;height:20px;font-size:12px;}
</style>
</head>
<body style="padding:10px">
<div class="navbar">
		<span>您当前的位置：</span>
		次品管理 &gt; 新增次品
</div>
<form name="form1" method="post" action="add_defective.do" id="form1" onsubmit="return setGridData()">
<input type="hidden" id="gridData" name="defectives" value=""> 
   <table  cellpadding="0" cellspacing="0" class="l-table-edit p-tab"" >
    <tr>
        <td align="right" class="l-table-edit-td s-lab"></td>
        <td align="left" width="100%" class="l-table-edit-td "></td>
        <td align="left"></td>
    </tr>
    <%-- <tr>
       <td align="right" width="100px;"  class="l-table-edit-td s-lab"><font  color="red">*</font>预计采购日期：</td>
       <td align="left" class="l-table-edit-td "> 
       <input id="prEstimatedDate" type="text" name="prEstimatedDate" readonly="readonly" value="${prv.prEstimatedDate }" class="Wdate l-textarea" value="" size="21"
    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'%y-%M-{%d+1}'})" validate="{required:true,rangelength:[10,18]}" /> 
       </td><td align="left"></td>
     </tr> --%>
     <%-- <tr>
       <td align="right" class="l-table-edit-td s-lab"><font  color="red">*</font>到货日期：</td>
       <td align="left" class="l-table-edit-td "> 
       <input id="prArriveDate" type="text" name="prArriveDate" readonly="readonly" value="${prv.prArriveDate }" class="Wdate l-textarea" value="" size="21"
    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'prEstimatedDate\')}'})" validate="{required:true,rangelength:[10,18]}" /> 
       </td><td align="left"></td>
     </tr> --%>
     
    
     <tr>
        <td align="right" class="l-table-edit-td s-lab">
        	<input type="button" value="选择商品" id="elect_product" class="l-button l-button-test" />
        </td>
        <td align="left" class="l-table-edit-td ">
        	<input type="hidden" id="productlist" name="productlist" />
        	<!-- <input type="button" onclick="valData();" value="ssss"  /> -->
        </td>
        <td align="left"></td>
     </tr>
      <tr id="xzProductList" style="display: none;">
     <tr>
        <td colspan="3" align="left" class="l-table-edit-td s-lab">
        <div id="maingrid" style="margin:0; padding:0"></div>
		  <div style="display:none;">
		  <!-- 展示列表数据  -->
		</div>
		</td>
     </tr>

</table>


<input type="submit" value="确定" id="submit1" class="l-button l-button-submit" /> 
<input type="button" value="取消" name="tests" id="tests" class="l-button l-button-test" />
</form>
</body>
<script>

var basePath ="${BasePath}";
$(document).ready(function(){

	//选择商品子窗口
	$("#elect_product").click(function(){
		list = new Array();
	   	var m =$.ligerDialog.open({
	   				title:'请购商品',
	   				url:'${BasePath}/product/defectivemgt/getCommodityList.do?selectOnlyRow=false',
	   				height:500,width:700,
	   				buttons: [{ text: '确定', onclick: function (item, dialog) { 
	   									dialog.frame.valProd();
	   									if(!dialog.frame.isOut) return false;
	   									addProduct(); 
	   									dialog.close(); 
	   								} 
	   						  },
	   				          { text: '取消', onclick: function (item, dialog) { dialog.close(); list = new Array();} } ],
	   				isResize: false, 
	   				isDrag: false 
	   		});
	   	m.show(); 
	});
	
	addProduct();
});
var dealWith = [
 	  	       {no:1,text:'退货'},
	  	      // {no:2,text:'换货'},
	  	       {no:3,text:'其他'},
	  	       {no:4,text:'无法修复'}
	  	       ];

//查询
var sel = "";
//临时请购商品集合
var list = new Array();
//请购商品集合
var commoditylist = new Array();
var g = "";
//请购商品列表
function addProduct(){
	commoditylist = commoditylist.concat(list);
	//$.ligerDialog.warn(JSON.stringify(commoditylist));
	commodityData = {"Rows": commoditylist, "Total": commoditylist.length};
	grid = $("#maingrid").ligerGrid({
        columns: [
        { display: '商品编号', name: 'commoNo' },
        { display: '商品名称', name: 'commoName' },
		{ display: '采购单号', name: 'poNo'},
		{ display: '供应商', name: 'supName' },
		{ display: '仓库名称', name: 'whName' },
      	{ display: '规格', name: 'specName'},
      	/* { display: '商品编号', name: 'prodNo'},
        { display: '货品条码', name: 'commoNo'},
        { display: '供应商', name: 'whName'},
        { display: '仓库名称', name: 'commoName'}, */
       /*  { display: '采购单号', name: 'purchaseNo',editor:{type:'string'}}, */
        { display: '库存良品数', name: 'yieldAmountNumner'},
        { display: '需转次品数', name: 'defectiveNumber',editor:{type:'int'},
             render:function(rowdata,rowindex,value){
				if(value == null || value == '' ){
          		   return "<font style='color: blue;font-size: 12px;'>请输入</font>";
          	   	}
				return value;
     		}
        },
        { display: '处理方式', name: 'dealWith',editor:{
    	  	type:'select',
    	  	data: dealWith,
    	  	valueField:"no",
    	  	textField:"text",
   		},render:function(rowdata,rowindex,value){
    	   if(value == null || value == '' ){
    		   return "<font style='color: blue;font-size: 12px;'>请选择</font>";
    	   }
           for (var i = 0; i < dealWith.length; i++){
               if (dealWith[i]['no'] == value){
                   return dealWith[i]['text']
               }
           		
    		}
   		}},
        { display: '次品原因', name: 'defectiveReason',editor:{type:'string'},
			render:function(rowdata,rowindex,value){
				if(value == null || value == '' ){
					return "<font style='color: blue;font-size: 12px;'>请输入</font>";
				}
	            return value;
       		}
        },
        
/*         { display: '备注', name: 'description',editor:{type:'string'},
           render:function(rowdata,rowindex,value){
    	   if(value == null || value == '' ){
    		   return "<font style='color: blue;font-size: 12px;'>请输入</font>";
    	   }
           return value;
        }}, */
        { display: '操作', isSort: false, render: function (rowdata, rowindex, value){
           	var  text = "<input type='button' value='删除' onclick='removeThis("+rowindex+");' />";
            return text;
        	}
        }
        ], 
        width: '100%',
        height: '330',
        usePager: false,enabledEdit: true,
        data: $.extend(true,{},commodityData)
    });
	list = new Array();
	//
	  g= $("#maingrid").ligerGrid({
		         grid: grid,
	 			pageSize:30,
	            width: '100%',
	            height: '92%',
	            dataType: 'server', 
	            dataAction: 'server',
	            pagesizeParmName: 'pageSize',
	            enabledEdit: true
	        });
	        
	//
}
	 function setGridData(){
	 		var data = g.getData();
	 		var dataStr = JSON.stringify (data);
	 		$('#gridData').val(dataStr);
	 		return true;
	}


//删除商品
function removeThis(o) {
	commoditylist.splice(o,1);
	addProduct();
}

//供应商编码
var scode ="";
//供应商名称
var sname="";
//成本价格
var actprice="";



//from提交
$(function ()
		{
			//validate
		    $.metadata.setType("attr", "validate");
		    var v = $("form").validate({
		        errorPlacement: function (lable, element)
		        {
		        	lable.ligerHideTip();
		            if (element.hasClass("l-textarea"))
		            {
		                element.ligerTip({ content: lable.html(), target: element[0] }); 
		            }
		            else if (element.hasClass("l-text-field"))
		            {
		                element.parent().ligerTip({ content: lable.html(), target: element[0] });
		            }
		            else
		            {
		                lable.appendTo(element.parents("td:first").next("td"));
		            }
		            
		        },
		        submitHandler:function()
		        {
		        	$("form .l-text,.l-textarea").ligerHideTip();
		        	/* valData(); */
		        /* 	if(!prod) return prod; */
		            var options = {
		            		type: 'POST',
		            		beforeSend: function(){
		            			$("#form1").find(":submit,:button").attr("disabled", true);
		            		},
		            		success: function(data){
		            			if(data=="success") {
		            				window.parent.f_tip('新增成功');
		            				close_liger_tab();
		            			} else {
		            				window.parent.f_tip('新增失败');
		            			}
		            		}
		            	}, $form1 = $("#form1");
		           $form1.ajaxSubmit(options);
		           return false;
		        }
		    });
}); 
// 取消
$("#tests").click(function() {
	close_liger_tab();
});	
</script>
</html>